/**
 * @description 全局前置守卫，不符合菜单导航的路由不再加载
 * 注意此处需要过滤掉页面内部触发的路由，如审计日志详情、退出系统等
 * @auhtor cuishoujia
 * @param {Object} to 要跳转至的导航
 * @param {Object} from 要离开的导航
 * @param {Object} next 守卫的放行函数，必须手动调用，参见官网
 */
export const beforeEachCB = function(to, from, next) {
    //需要放行的router，这些router在navList中没有配置
    let passRouter=["home","login","changePassword","auditLogDetail"];

    if (passRouter.includes(to.name)) return next();

    if (!this.navList) return next();
    
    let res = this.navList.some(item => {
        if (item.name === to.name) return true;
        if (item.children && item.children.length){
            return item.children.some(child => child.name === to.name);
        }
        return false;
    });
    next(res);
}